package net.fishbowlmedia.scroller3d.view  {
	
	import org.papervision3d.core.proto.CameraObject3D;	
	import org.papervision3d.view.Viewport3D; 
	import org.papervision3d.cameras.*; 
	import org.papervision3d.scenes.Scene3D; 
	import org.papervision3d.render.BasicRenderEngine; 
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class PaperVisionBase extends Sprite { 
		
		public var viewport:Viewport3D; 
		public var renderer:BasicRenderEngine; 
		public var currentScene:Scene3D;
		public var currentCamera:CameraObject3D;
		public var currentViewport:Viewport3D;
		public var defaultScene:Scene3D; 
		public var defaultCamera:FreeCamera3D; 
		
		protected function init(vpWidth:Number = 800, vpHeight:Number = 600):void 
		{
			initPapervision(vpWidth, vpHeight); 
			init3d(); 
			init2d(); 
			initEvents(); 
		}
		protected function initPapervision(vpWidth:Number, vpHeight:Number):void 
		{
			if (vpWidth == 0) viewport = new Viewport3D(stage.width, stage.height, true, true);
			else viewport = new Viewport3D(vpWidth, vpHeight, false, true);
						
			addChild(viewport); 
			
			renderer = new BasicRenderEngine();
			
			defaultScene = new Scene3D();
			
			defaultCamera = new FreeCamera3D();
			
			currentCamera = defaultCamera;
			currentScene = defaultScene;
			currentViewport = viewport;
		}
		protected function init3d():void 
		{			
		}
		protected function init2d():void 
		{	
		}
		protected function initEvents():void 
		{
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		protected function processFrame():void 
		{
		}
		protected function onEnterFrame( ThisEvent:Event ):void 
		{	
			processFrame();
			renderer.renderScene(currentScene, currentCamera, currentViewport);
		}
	}
}